package com.pzb.web.controller.page;

import java.util.List;

import com.pzb.market.domain.MkGroupbuying;
import com.pzb.wechat.service.IWechatAppletService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pzb.common.annotation.Log;
import com.pzb.common.core.controller.BaseController;
import com.pzb.common.core.domain.AjaxResult;
import com.pzb.common.enums.BusinessType;
import com.pzb.page.domain.PgSearch;
import com.pzb.page.service.IPgSearchService;
import com.pzb.common.utils.poi.ExcelUtil;
import com.pzb.common.core.page.TableDataInfo;

/**
 * 搜索管理Controller
 * 
 * @author Mr_Wu
 * @date 2021-12-27
 */
@RestController
@RequestMapping("/page/search")
public class PgSearchController extends BaseController
{
    @Autowired
    private IPgSearchService pgSearchService;
    @Autowired
    private IWechatAppletService wechatAppletService;

    /**
     * 查询搜索管理列表
     */
    @PreAuthorize("@ss.hasPermi('page:search:list')")
    @GetMapping("/list")
    public TableDataInfo list(PgSearch pgSearch)
    {
        pgSearch.setExtAppid(wechatAppletService.getExtAppid());
        startPage();
        List<PgSearch> list = pgSearchService.selectPgSearchList(pgSearch);
        return getDataTable(list);
    }

    /**
     * 获取搜索管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('page:search:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pgSearchService.selectPgSearchById(id));
    }

    /**
     * 新增搜索管理
     */
    @PreAuthorize("@ss.hasPermi('page:search:add')")
    @Log(title = "搜索管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PgSearch pgSearch)
    {
        String extAppid = wechatAppletService.getExtAppid();
        if("1".equals(extAppid)){
            return AjaxResult.error("您还没有小程序!");
        }
        pgSearch.setExtAppid(extAppid);
        return toAjax(pgSearchService.insertPgSearch(pgSearch));
    }

    /**
     * 修改搜索管理
     */
    @PreAuthorize("@ss.hasPermi('page:search:edit')")
    @Log(title = "搜索管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PgSearch pgSearch)
    {
        return toAjax(pgSearchService.updatePgSearch(pgSearch));
    }

    /**
     * 删除搜索管理
     */
    @PreAuthorize("@ss.hasPermi('page:search:remove')")
    @Log(title = "搜索管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pgSearchService.deletePgSearchByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('page:search:edit')")
    @Log(title = "搜索管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody PgSearch pgSearch)
    {
        return toAjax(pgSearchService.updatePgSearch(pgSearch));
    }
}
